home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / MATV.ZIP / LOTTO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  1.1 KB  |  51 lines

  1. /* a little freebe for those of you who yearn for simpler days */
  2. /* a Texas Pick Six Lotto Program in ANSI C without floating point*/
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7.  
  8. void shuffle( int n, int x[] )
  9. {
  10.    /* generate a random index to swap with */
  11.    int i,j,t;
  12.    for( i = 0;  i<n; i++){
  13.          j = rand() % n;
  14.          t = x[i];
  15.       x[i] = x[j];
  16.       x[j] = t;
  17.       if( !(i%2) ) printf("%3d\r",j);
  18.    }
  19.    printf("   \r");
  20. }
  21.  
  22. int sort_function( const void *a, const void *b)
  23. {
  24.    return ( *((int *) a) < *((int *)b) ) ? -1 : 1;
  25. }
  26.  
  27. main( )
  28. {
  29.    int i,j, x[6][50], n=50;
  30.    time_t t;
  31.  
  32.    /* seed the random number generator with the clock */
  33.    srand( (unsigned) time( &t ) );
  34.    for( i=0; i<6; i++)
  35.       for( j=0; j<50; j++) x[i][j] = j;
  36.  
  37.    printf("\nRoll the magic 50 sided die\n");
  38.    for( i=0; i<6; i++) shuffle( n, x[i] );
  39.  
  40.    for( i=0; i<6; i++)
  41.       qsort( (void *)(x[i]), 6, sizeof(int), sort_function);
  42.  
  43.    printf("\nYour Lucky Lotto Pick 6 Draws are \n\n");
  44.    for( i=0; i<6; i++){
  45.        printf("%d:",i+1);
  46.        for( j=0; j<6; j++) printf("%3d", x[i][j]+1 );
  47.        printf("\n");
  48.    }
  49.    return 0;
  50. }
  51.